package cn.rengy.isql.lang;

public class _StopWatch {
    // Scales as constants
    private static final long NANO_SCALE   = 1L;//纳秒
    private static final long MICRO_SCALE  = 1000L * NANO_SCALE;//微秒
    private static final long MILLI_SCALE  = 1000L * MICRO_SCALE;//毫秒
    private static final long SECOND_SCALE = 1000L * MILLI_SCALE;//秒
    private static final long MINUTE_SCALE = 60L * SECOND_SCALE;
    private static final long HOUR_SCALE   = 60L * MINUTE_SCALE;
    private static final long DAY_SCALE    = 24L * HOUR_SCALE;

    public static String spendFormat(long durationNano){
        StringBuilder sb=new StringBuilder();
        long seconds = durationNano /  SECOND_SCALE;
        if(seconds>0){
            durationNano = durationNano - (seconds * SECOND_SCALE);
            sb.append(seconds).append("s");
        }
        long milli= durationNano /  MILLI_SCALE;
        if(milli>0){
            sb.append(milli).append(".");
            durationNano = durationNano - (milli * MILLI_SCALE);
            long micro= durationNano /  MICRO_SCALE;
            sb.append(micro);
            sb.append("ms");
        }
        return sb.toString();
    }
}
